package com.qianclass.talklive.app.json.ImSendMessge;

import com.qianclass.talklive.app.bean.RaiseHandBean;
import com.qianclass.talklive.app.im.IMEgine;
import com.qianclass.talklive.app.utils.Constant;
import com.qianclass.talklive.app.utils.LogUtil;
import com.qianclass.talklive.app.utils.ThreadUtils;
import com.google.gson.Gson;


/**
 * 举手发言 \ 取消举手发言
 */

public class SendRaiseHandMessge {

    /**
     * @param isHand 是否举手发言
     * @param useracount 举手用户的 Acount
     * @param userid 举手用户的 id
     * @param egine
     * @param group
     */
    public static void sendMessge(boolean isHand, String useracount, int userid, final IMEgine egine, final String group) {
        try {
            RaiseHandBean mRaiseHandBean = new RaiseHandBean();
            RaiseHandBean.MessageBean messageBean = new RaiseHandBean.MessageBean();
            if (isHand) {
                messageBean.setSubcommand("handup");
            }else {
                messageBean.setSubcommand("cancelhandup");
            }
            messageBean.setType("member");
            messageBean.setUseracount(useracount);
            messageBean.setUserid(userid);
            mRaiseHandBean.setMessage(messageBean);

            Gson gson = new Gson();
            final String jsonString = gson.toJson(mRaiseHandBean);
            ThreadUtils.runOnSubThread(new Runnable() {
                @Override
                public void run() {
                    egine.SendGroupMessage(Constant.CONTROLMSGTYPE, group, jsonString);
                }
            });
            LogUtil.i("举手发言/取消举手发言" ,jsonString);
        } catch (Exception e){
            LogUtil.i("举手发言/取消举手发言" , "发送信息失败");
        }

    }
}
